#!/bin/bash

# Here we figure out DL_SERVER, SOURCE_ROOT, WEB_DIR, etc.
. functions.sh

echo_and_log "--> Starting Vagrant provision7.sh..."


# All YUM repo work has been moved to pre_provision.sh

# Setting up PHP and Apache server
./_setup_apache.sh .. vagrant

# Prepare the composer files
./prepare_composer.sh

# Create the necessary tables/users for MySQL.
echo_and_log "--> Creating DEV and TESTING databases for UCX"
sudo $SOURCE_ROOT/vagrant/createdb.sh ucx   ucx    ucx
sudo $SOURCE_ROOT/vagrant/createdb.sh ucx_t ucx_t  ucx_t

echo_and_log "--> Migrating database schema..."
# Run database migrations
 sudo $WEB_DIR/yii migrate --interactive=0
echo_and_log "--> Migrating admin@fp.com as full-function ..."
 sudo $WEB_DIR/yii upgrade-full-function admin@fp.com


# Create sym-link to phpmyadmin if needed
#if [ ! -L $WEB_DIR/web/phpmyadmin ]; then
    #sudo ln -s $WEB_DIR/vendor/fillup/phpmyadmin-minimal $WEB_DIR/web/phpmyadmin
#fi

#Setup cloud service
echo_and_log "--> Invoking serviceplayer.sh"
sudo $SOURCE_ROOT/vagrant/servicelayer.sh

#codecept
sudo cp /vagrant/webapp/tests/codecept.phar /usr/bin/codecept
sudo chmod +x /usr/bin/codecept

echo_and_log "--> Provision.sh finished in ${SECONDS}s"
